package com.zx.chatroom.util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.zx.framework.core.util.StringUtil;

public class baseUtil {

	
	/**
     * gson时间格式化
     */
    private String gsonDateFormat = "yyyy-MM-dd HH:mm:ss";
    /**
     * 输出格式化 用于调试
     */
    private boolean prettyPrinting = false;

    protected GsonBuilder builder = new GsonBuilder();

    protected Gson gson = getGson();

    /**
     * 获取gson对象
     *
     * @return
     */
    protected Gson getGson() {

        if (StringUtil.isNotEmpty(gsonDateFormat)) {
            builder.setDateFormat(gsonDateFormat);
        }
        if (prettyPrinting) {
            builder.setPrettyPrinting();
        }
        builder.serializeNulls();
        return builder.create();
    }
}
